// 分类接口管理
import request from "@/utils/request";
import type {
  CategoriesResponse,
  CategoryEditResponse,
  CategoryResponse,
  CategoryType,
} from "./types";

enum API {
  CATEGORY_LIST = "/wx/category/list",
  CATEGORY_CREATE_OR_EDIT = "/wx/category/createOrEdit",
  CATEGORY_GET_BY_ID = "/wx/category//getById",
  CATEGORY_REMOVE = "/wx/category/remove",
  CATEGORY_CHANGE_STATUS = "/wx/category/changeStatus",
}

export const list = (data: CategoryType) =>
  request.post<any, CategoriesResponse>(API.CATEGORY_LIST, data);

export const categoryCreateOrEdit = (data: CategoryType) =>
  request.post<any, CategoryEditResponse>(API.CATEGORY_CREATE_OR_EDIT, data);

export const categoryGetById = (id: number) =>
  request.get<any, CategoryResponse>(API.CATEGORY_GET_BY_ID + `/${id}`);

export const categoryRemove = (id: number) =>
  request.delete<any, CategoryEditResponse>(API.CATEGORY_REMOVE + `/${id}`);

export const categoryChangeStatus = (id: number, status: number) =>
  request.post<any, CategoryEditResponse>(
    API.CATEGORY_CHANGE_STATUS + `/${id}` + `/${status}`
  );
